#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

vector<int> intersection(vector<int>& nums1, vector<int>& nums2)
{
    unordered_set<int> result_set; // 存放结果
    unordered_set<int> nums_set(nums1.begin(), nums1.end());
    for (int num : nums2)
    {
        // 发现nums2的元素 在nums_set里又出现过
        if (nums_set.find(num) != nums_set.end()) 
        {
            result_set.insert(num);
        }
    }
    //return vector<int>(result_set.begin(), result_set.end());
    for(vector<int>::iterator it = result_set.begin(); it!=result_set.end(); ++it) 
    {
        cout << *it<< " ";
    }
    cout << endl;
}

